package com.legendframework.core.ioc.impl;

import com.legendframework.core.Store;
import com.legendframework.core.aop.AbstractProxy;
import com.legendframework.core.ioc.CommonBeansGenerate;
import com.legendframework.core.ioc.annotation.MainPlugin;
import com.legendframework.core.AbstractLegendPlugin;
import com.legendframework.core.support.lang3.StringUtils;
import com.legendframework.core.dao.Return;

import java.lang.annotation.Annotation;

/**
 * @see MainPlugin 方式的Bean注入类型
 */
public class  LegendPluginBeansGenerate extends CommonBeansGenerate {

    public LegendPluginBeansGenerate(Store store) {
        super(store);
    }

    @Override
    public String getBeanName(Class<?> cls) {
        return StringUtils.isEmpty(cls.getAnnotation(MainPlugin.class).value()) ? cls.getName() : cls.getAnnotation(MainPlugin.class).value();
    }

    @Override
    public Class<? extends Annotation> getAnnotation() {
        return MainPlugin.class;
    }

    @Override
    protected Return<String, Object> newInstance(Class<?> cls , AbstractLegendPlugin plugin) {
        return Return.build(getBeanName(cls),injectionBean(getBeanName(cls),plugin,plugin));
    }

    @Override
    protected AbstractProxy getProxyAop() {
        return null;
    }
}
